package com.chengqs.test_object;

import java.io.IOException;
import java.util.Scanner;

/**
 * 禁用执政压缩
 * -XX:-UseCompressedOops -XX:-UseCompressedClassPointers
 */
public class test {
    public static void main(String[] args) throws InterruptedException {
        Cat cat = new Cat(10);
        cat.behavior(); // 0x0000001102834701 --> 没有变成锁的 mark_word (后两位bit位为01)
        Thread.sleep(5000);
        // System.out.println(cat);
        new Thread(() -> {
            // System.out.println(cat);
        }, "t0").start();
        Thread.sleep(500);
        new Thread(() -> {
            synchronized (cat) {
                System.out.println(cat); // 0x000000d0224ff470 --> 变成轻量级锁的 mark_word (后两位bit位为00)
                synchronized (cat) {
                    System.out.println(cat);
                    try {
                        Thread.sleep(1000 * 60 * 60);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "t1").start();
        Thread.sleep(500);
        new Thread(() -> {
            System.out.println(cat);
            synchronized (cat) {
                System.out.println(cat); // 0x0000013fff1919fa --> 变成重量级锁的 mark_word (后两位bit位为10)
                                         // 0x0000007bFb179c8a
            }
        }, "t2").start();
    }
}
